#!/usr/bin/perl
# diskswap.cgi in diskman

require './diskman-lib.pl';
&error_setup("Error");
&ReadParse();
$diskindex = $in{'disk'};
if ($diskindex =~ /^(\d+)/) {
    $nn = $1;
}
@disks = get_all_lsi_diskinfo(); 
my $extmark = 1;
foreach $dd (@disks) {
	if ($dd->{'es'} eq $diskindex) {
		$extmark=0;
		$dhsp = $dd;
		last;
	}
}
if ($diskindex =~ /(\d+)/) {
    $dnum = $1 - 1;
}
$des = $dhsp->{'es'};
$uid = $dhsp->{'status'};
#&error($uid);
if( $uid =~ /Hotspare/ ) {
    system("/sbin/MegaCli -PDHSP -Rmv -PhysDrv[$des] -a0");
}
elsif ($uid =~ /good/) {
    system("/sbin/MegaCli -PDHSP -Set -PhysDrv[$des] -a0");

}

&redirect("index.cgi");


